﻿
var Certificate;
var CSCode;
var CLCode;
var selAll;
var DropQual;
var DropSubQual;
var level = "-1";
var specil = "-1";
var empCertType = "ZGZSLC";
var itemFlag = "0";
var itemType = "";
/*************************人员资格***************************/

///根据传递的参数取得证书类别下拉列表框数据
function SelCertList(rootCode, parentId, sel, vals, child) {
    $.getJSON("../Person/PersonEmpCertInfo14.aspx", { "action": "GetQualitiesDic", "rootCode": rootCode, "parentId": parentId, "itemFlag": itemFlag, "itemType": itemType, "rand": Math.random() }, function (data) {
        $("#" + sel).empty();
        SetDefaultSelVal(sel);
        if (data != null && data.length > 0) {
            SetOptionVals(data, sel, vals);
            if (child != "") {
                BindCertLevel(level);
                BindCertSpecialty(specil);
            }
        }
    });
}
///取得下拉列表框数据
function SelCertAll(rootCode, parentId, sel, vals, child) {
    $.getJSON("../Person/PersonEmpCertInfo14.aspx", { "action": "GetQualitiesDic", "rootCode": rootCode, "parentId": parentId, "rand": Math.random() }, function (data) {
        $("#" + sel).empty();
        SetDefaultSelVal(sel);
        if (data != null && data.length > 0) {
            SetOptionVals(data, sel, vals);
            if (child != "") {
                BindCertLevel(level);
                BindCertSpecialty(specil);
            }
        } else {
            //等级特殊处理
            if (sel == CLCode) {
                $("#" + CLCode).find("option:selected").text("不分等级");
            }
        }
    });
}
/*添加下拉列表内容*/
function SetOptionVals(data, sel, vals) {
    $("#" + sel).empty();
    SetDefaultSelVal(sel);
    for (var i = 0, j = data.length; i < j; i++) {
        var item = data[i];
        $("#" + sel).append("<option value='" + item.Code + "' vls='" + item.Id + "'>" + item.Title + "</option>");
    }
    if (vals != "-1") {
        $("#" + sel).val(vals);
    }
}
/*证书类别联动*/
function SelCertChange() {
    $("#" + CSCode).val("-1");
    BindCertLevel("-1");
    BindCertSpecialty("-1")
}
/*专业*/
function BindCertSpecialty(code) {
    var parentId = $("#" + Certificate).find('option:selected').attr("vls");
    var parentVal = $("#" + Certificate).find('option:selected').val();
    if (parentId == "-1") {
        $("#" + CSCode).empty();
        SetDefaultSelVal(CSCode);
        return false;
    }
    SelCertAll("specialty", parentId, CSCode, code, "");
}
/*证书等级*/
function BindCertLevel(code) {
    if (CLCode == "undefined")
        return false;
    var parentId = $("#" + Certificate).find('option:selected').attr("vls");
    if (parentId == "-1") {
        $("#" + CLCode).empty();
        SetDefaultSelVal(CLCode);
        return false;
    }
    SelCertAll("ZGDJ", parentId, CLCode, code, "");

}
function SetDefaultSelVal(selId) {
    $("#" + selId).append("<option value='-1' vls='-1'>请选择</option>");
}

/****************************评审资格**********************************/
///取得评审资格全部
function selPostAll() {
    $.getJSON("../Handlers/PsnEmpInfoHandler.ashx", { "action": "PostPszg", "rand": Math.random() }, function (data) {
        selAll = data;
        SetSelParentVal();
    });
}
function SetSelParentVal() {
    $("#" + DropQual).empty();
    $("#" + DropQual).append("<option value='-1'>请选择</option>");
    if (selAll == null || selAll == "undefined") {
        return;
    }
    for (var x in selAll) {
        if (x.length > 2) {
            continue;
        }
        $("#" + DropQual).append("<option value='" + x + "'>" + selAll[x] + "</option>");
    }
}
///评审资格选择
function SelChange() {
    var post1 = $("#" + DropQual).val();
    $("#" + DropSubQual).empty();
    $("#" + DropSubQual).append("<option value='-1'>请选择</option>");
    if (post1 == "-1") {
        return;
    }
    if (selAll == null || selAll == "undefined") {
        return;
    }
    for (var x in selAll) {
        if (x.length <= 2) {
            continue;
        }
        if (x.substring(0, 2) == post1) {
            $("#" + DropSubQual).append("<option value='" + x + "'>" + selAll[x] + "</option>");
        }
    }
}

